<!--
 * @Description: 泵车维护
 * @Autor: wangwangwang
 * @Date: 2021-03-30 15:33:45
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-06-03 14:33:22
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span>
                <span style="margin-right: 12px;">泵自编码</span>
                <el-input v-model="tableParam.code" style="width: 240px;" placeholder="请输入" clearable @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">泵类型</span>
                <el-select v-model="tableParam.typeId" style="width: 240px;" placeholder="请选择">
                  <el-option v-for="item in equipmentTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="tableParamType = true">高级搜索</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="addFromDate('添加')">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='RIYONG'))!==-1" size="small" class="bottom_three" @click="Update(1)">
                <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px;"></i>
                启用
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='JINYONG'))!==-1" size="small" class="bottom_four" @click="Update(0)">
                <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px;"></i>
                禁用
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='BCJCXPZ'))!==-1" size="small" class="botton_five" @click="openDialog()">泵车检查项配置</el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='EWEIM'))!==-1" size="small" class="bottom_four" @click="handleDown">
                批量下载
              </el-button>
            </div>
            <div>
              <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='BAOCUNPXH'))!==-1" :underline="false" @click="SortNum()">
                <span class="el-icon--left">
                  <i class="iconfont iconicon_button_sort1"></i>
                </span>
                保存排序号
              </el-link>
              <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
                <el-link :underline="false">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_filtrate"></i>
                  </span>
                  筛选
                </el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item, index) in table" :key="index">
                    <el-checkbox v-model="item.status">{{ item.label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
                <span class="el-icon--left">
                  <i class="iconfont iconicon_button_export1"></i>
                </span>
                导出
              </el-link>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <el-table-column align="center" type="selection"></el-table-column>
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed=" (item.label =='操作'||item.label =='二维码')?'right':false">
                  <template slot-scope="scope">
                    <span v-if="scope.row.enable == 0 && item.label == '状态'" style="color:#969799;">禁用</span>
                    <span v-if="scope.row.enable == 1 && item.label == '状态'" style="color:#00A754;">启用</span>
                    <div v-if="item.label == '二维码'&&scope.row.quickMarkUrl &&ButtonList.findIndex(res=>(res.buttonValue=='EWEIM'))!==-1 " class="table_link">
                      <a :href="'/file/' +scope.row.quickMarkUrl" download>下载</a>
                    </div>
                    <div v-if="item.label == '二维码'" class="table_link" style="cursor: pointer;">
                      <div @click="showPreview(scope.row)">预览</div>
                    </div>
                    <el-button v-if="item.label == '操作'" class="bottom_one" size="mini" @click="updateFromDate(scope.row, '修改')">
                      修改
                    </el-button>
                    <el-button v-if="item.label == '操作'" class="bottom_one" size="mini" @click="maintenance(scope.row)">设备维护</el-button>
                    <div v-if="item.label == '排序号'">
                      <el-input v-model="scope.row.sortNum"></el-input>
                    </div>
                    <span v-if="item.label !== '操作' && item.label !== '排序号' && item.label !== '状态' && item.label !== '二维码'">{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 添加 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="480px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="typeId">
            <span slot="label" style="color: #FF0000 ;">泵类型</span>
            <el-select v-model="fromDate.typeId" placeholder="请选择">
              <el-option v-for="item in equipmentTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="plateNumbers">
            <span slot="label" style="color: #FF0000 ;">车牌/编号</span>
            <el-input v-model="fromDate.plateNumbers" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item v-if="UserInfo.adminStatus == 1" prop="companyId">
            <span slot="label">所属单位</span>
            <el-select v-model="fromDate.companyId" placeholder="请选择" @change="setstationIdlist(),$nextTick(()=>{fromDate.company = $refs.selection1.selectedLabel})">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="stationId">
            <span slot="label">站点名称</span>
            <el-select ref="selection2" v-model="fromDate.stationId" placeholder="请选择" @change="get_simple_organizationFun(fromDate.stationId),$nextTick(()=>{fromDate.stationName = $refs.selection2.selectedLabel})">
              <el-option v-for="item in stationIdlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="enable">
            <span slot="label">状态</span>
            <el-radio-group v-model="fromDate.enable">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="pagessubmitFromDate()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 设备维护 -->
    <el-dialog v-dialogDrag :visible.sync="maintenanceDialog" width="1072px" :close-on-click-modal="false" :before-close="resetOtherFromDate">
      <span slot="title" class="dialog-title">泵维护</span>
      <div class="dialogOtherinfo">
        <div class="nav-one" style="min-height: 530px;">
          <div class="navone-nav">
            <template v-for="(item, index) in navlist">
              <div :key="index" :class="navindex == item.id ? 'active' : ''" @click="navindex = item.id">{{ item.name }}</div>
            </template>
          </div>
          <div v-if="navindex == 1" class="navone-info">
            <el-form :inline="true" label-width="110px">
              <el-form-item>
                <span slot="label">故障类型</span>
                <el-select v-model="maintenanceData.typeId" placeholder="请选择">
                  <el-option v-for="item in MaintenanceType" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <span slot="label">维修时间</span>
                <el-date-picker v-model="maintenanceData.daintainTime" type="datetime" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
              <el-form-item>
                <span slot="label">备 注</span>
                <el-input v-model="maintenanceData.remark" placeholder="请输入" class="textarea" type="textarea" resize="none" rows="10" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div v-if="navindex == 2" class="navone-info">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="maintenancelist" tooltip-effect="dark">
              <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
              <el-table-column prop="typeName" label="故障类型" width="180" align="center"></el-table-column>
              <el-table-column prop="daintainTime" label="维修时间" width="180" align="center"></el-table-column>
              <el-table-column prop="remark" label="备注" width="auto" align="center"></el-table-column>
              <el-table-column prop="updateTime" label="更新时间" width="180" align="center"></el-table-column>
            </el-table>
            <el-pagination :current-page.sync="maintenanceParam.page" :page-size="maintenanceParam.pageSize" layout="prev, pager, next, jumper" :total="maintenancetotal" @current-change="getmaintenancelist()"></el-pagination>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetOtherFromDate">取 消</el-button>
        <el-button v-if="navindex == 1" class="bottom_all" style="margin-left: 24px;" @click="submitmaintenance()">提 交</el-button>
      </span>
    </el-dialog>
    <!-- 泵车检查项配置 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog1" width="880px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">泵车检查项配置</span>
      <div>
        <div>
          <span style="margin-left: 24px;">
            <span style="margin-right: 12px;">泵车类型</span>
            <el-select v-model="form1.typeId" style="width: 240px;" placeholder="请选择" @change="gettable1()">
              <el-option v-for="item in equipmentTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </span>
          <span style="margin-left: 24px;">
            <span style="margin-right: 12px;">公司</span>
            <el-select v-model="form1.companyId" style="width: 240px;" placeholder="请选择" @change="gettable1()">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </span>
        </div>
        <div style="padding:15px 0">
          <el-button size="mini" class="bottom_all" style="margin-left: 0" :disabled="!form1.companyId" @click="Additem()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
            添加
          </el-button>
        </div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="table1" tooltip-effect="dark">
          <el-table-column align="center" label="检查项" prop="checkItem"></el-table-column>
          <el-table-column align="center" label="输入类型">
            <template slot-scope="scope">
              {{scope.row.inputType==1?'文本输入':'下拉选择'}}
            </template>
          </el-table-column>
          <el-table-column align="center" width="200" label="操作">
            <template slot-scope="scope">
              <el-button class="bottom_one" size="mini" @click="upDateitem(scope.row)">
                修改
              </el-button>
              <el-button size="mini" class="bottom_two" @click="DelItem(scope.row,scope.$index)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog1=false">关 闭</el-button>
      </span>
    </el-dialog>
    <el-dialog v-dialogDrag :visible.sync="Dialog2" width="480px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">添加/修改检查项</span>
      <div class="dialoginfo">
        <el-form ref="refform2" :rules="rules2" :inline="true" :model="form2" label-width="110px">
          <el-form-item prop="checkItem">
            <span slot="label">检查项</span>
            <el-input v-model="form2.checkItem" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="inputType">
            <span slot="label">输入类型</span>
            <el-radio-group v-model="form2.inputType" @change="name2 = ''">
              <el-radio :label="1">文本输入</el-radio>
              <el-radio :label="2">下拉选择</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="form2.inputType==2" prop="inputType">
            <span slot="label">设置下拉选项</span>
            <div v-for="(item,index) in table2" :key="index" class="content">
              <div>{{item.name}}</div>
              <div>
                <el-button size="mini" class="bottom_two" @click="Deljson(index)">
                  <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                  删除
                </el-button>
              </div>
            </div>
            <div class="content">
              <div>
                <el-input v-model="name2" placeholder="请输入" clearable></el-input>
              </div>
              <div>
                <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="Addjson()">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  添加
                </el-button>
              </div>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog2=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="submit2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 高级搜索 -->
    <el-dialog v-dialogDrag :visible.sync="tableParamType" width="650px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">高级搜索</span>
      <div class="dialoginfo">
        <el-form ref="reftableParam" :inline="true" label-width="110px">
          <el-form-item >
            <span slot="label">所属单位</span>
            <el-input v-model="tableParam.company" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">站点</span>
            <el-input v-model="tableParam.stationName" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item >
            <span slot="label">车牌号</span>
            <el-input v-model="tableParam.plateNumbers" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">状态</span>
            <el-select v-model="tableParam.enable" placeholder="请选择" style="width:400px;">
              <el-option label="禁用" value="0"></el-option>
              <el-option label="启用" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="tableParamType=false,tableParam.company='',tableParam.stationName='',tableParam.plateNumbers='',tableParam.enable=''">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="gettableData(),tableParamType=false">搜 索</el-button>
      </span>
    </el-dialog>
    <!-- 查看图片 -->
    <ShowDetails :dialog="imgsDialog" imgsText="预览二维码" :imgList="imgList" :mp4List="[]" :fileList="[]" @reset="imgsDialog=false"></ShowDetails>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import ShowDetails from '@/components/showdetails';
import {
  queryPage,
  batchUpdateOrDelete,
  updateSortNum,
  saveOrUpdate,
  Download,
  equipmentMaintainQueryPagee,
  equipmentMaintainsave,
  setcheckItem,
  deletescheckItem,
  getListcheckItem,
} from "@/api/basicConfig/equipment.js";
import { getDicType, getUserAutList, get_simple_organization, permissionsCompanyList } from "@/api/common.js";
import { getUserInfo } from "@/utils/auth.js";
import { get_station_list } from "@/api/smart/stocksake.js";
import { carReg } from "@/common/RegExp.js";
export default {
  components: {
    ShowDetails
  },
  mixins: [mixin],
  data() {
    var validatePass1 = (rule, value, callback) => {
      if (value == "") {
        callback();
      }
      if (carReg(value)) {
        callback();
      } else {
        callback(new Error("请输正确的车牌号!"));
      }
    };
    return {
      imgsDialog: false,
      tableParamType: false,
      UserInfo: '',
      validatePass1: validatePass1,
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      updateSortNum: updateSortNum,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        {
          label: "泵自编码",
          width: "120",
          prop: "code",
          status: true,
        },
        {
          label: "车牌号",
          width: "140",
          prop: "plateNumbers",
          status: true,
        },
        {
          label: "所属单位",
          width: "180",
          prop: "company",
          status: true,
        },
        {
          label: "站点名称",
          width: "160",
          prop: "stationName",
          status: true,
        },
        {
          label: "二维码",
          width: "130",
          prop: "stationName",
          status: true,
        },
        {
          label: "泵类型",
          width: "140",
          prop: "typeName",
          status: true,
        },
        { label: '排序号', width: '120', prop: 'sortNum', status: true },
        {
          label: "状态",
          width: "120",
          prop: "useMode",
          status: true,
        },
        {
          label: "更新时间",
          width: "160",
          prop: "updateTime",
          status: true,
        },
        {
          label: "操作",
          width: "200",
          prop: "",
          status: true,
        },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        code: [
          {
            required: true,
            message: "请输入设备自编码",
            trigger: "blur",
          },
        ],
        stationId: [
          {
            required: true,
            message: "请选择站点",
            trigger: "change",
          },
        ],
        plateNumbers: [
          {
            required: true,
            message: "请输入",
            trigger: "blur",
          },
        ],
        typeId: [
          {
            required: true,
            message: "请选择设备类型",
            trigger: "change",
          },
        ],
        companyId: [
          {
            required: true,
            message: "请选择单位",
            trigger: "change",
          },
        ],
      },
      fromDate: {
        code: "", //自编码
        typeName: "",
        typeId: "",
        plateNumbers: '',
        stationName: "",
        stationId: "",
        company: "",
        companyId: "",
        enable: 1, //1启用 0禁用
      },
      companylist: [],
      equipmentTypelist: [],
      maintenanceDialog: false,
      navlist: [
        {
          name: "录入维修结果",
          id: 1,
        },
        {
          name: "设备维修记录",
          id: 2,
        },
      ],
      maintenanceParam: {
        page: 1,
        pageSize: 9,
      },
      maintenanceData: {
        typeName: "",
        typeId: "",
        daintainTime: "",
        remark: "",
      },
      maintenancelist: [],
      maintenancetotal: "",
      navindex: 1,
      stationIdlist: [],
      showtype: false,
      typelist: [],
      MaintenanceType: [],
      /**检查项配置*/
      Dialog1: false,
      Dialog2: false,
      form1: {
        typeId: "",
      },
      table1: [],
      form2: {
        checkItem: "",
        inputType: 1, //1文本框，2下拉框
        content: "", //下拉框内容json字符串
      },
      rules2: {
        checkItem: [
          {
            required: true,
            message: "请输入检查项",
            trigger: "biur",
          },
        ],
      },
      name2: "",
      table2: [],
      imgList: [],
      selectRow: [],
    };
  },
  async created() {
    this.UserInfo = await getUserInfo();
    this.companylist = await permissionsCompanyList();
    this.stationIdlist = await getUserAutList(true)
    this.tableParam = { ...this.tableParam, code: "", typeId: "", company: '', stationName: '', plateNumbers: '', enable: '' };
    this.gettableData();
    this.gettypeList();
    getDicType({ code: "MaintenanceType" }).then((res) => {
      this.MaintenanceType = res.data.items;
    });
  },
  methods: {
    handleSelectionChange (selectRow) {
      this.selectRow = selectRow;
    },
    handleDown () {
      if (!this.selectRow.length) {
        this.$message.warning('请选择要下载的数据')
        return
      }
      for (let i = 0; i < this.selectRow.length; i+=1) {
        let link = document.createElement('a');
        link.href = '/file/' +this.selectRow[i].quickMarkUrl;
        link.download = `${this.selectRow[i].plateNumbers}.png`;
        link.click();
        window.URL.revokeObjectURL(link.href);
      }
    },
    showPreview (data) {
      let items = data.quickMarkUrl?.split(",").map(res => ('/file/' + res))
      this.imgList = items;
      this.imgsDialog = true;
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.fromDate.companyId = res.data.id
        this.fromDate.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    setstationIdlist() {
      if (this.fromDate.companyId) {
        get_station_list({ parentId: this.fromDate.companyId }).then((res) => {
          this.stationIdlist = res.data;
        });
      }
    },
    /**
     * 检查项配置
     */
    openDialog() {
      this.Dialog1 = true;
      this.form1.typeId = '';
      this.form1.companyId = '';
      this.table1 = [];
    },
    gettable1() {
      if (this.form1.companyId && this.form1.typeId) {
        getListcheckItem(this.form1).then((res) => {
          this.table1 = res.data;
        });
      }
    },
    DelItem(row, index) {
      deletescheckItem({ id: row.id }).then(res => {
        if (res.code * 1 === 1001) {
          this.$message.success('删除成功')
          this.table1.splice(index, 1);
        }
      })
    },
    Additem() {
      if (this.form1.companyId == '') {
        this.$message({
          message: "请选择公司！",
          type: "warning",
        });
      } else {
        this.Dialog2 = true;
        this.$data.form2 = this.$options.data().form2;
        this.$data.table2 = this.$options.data().table2;
        this.form2.typeId = this.form1.typeId;
        setTimeout(() => {
          this.$refs.refform2.clearValidate();
        }, 10);
      }
    },
    upDateitem(data) {
      this.Dialog2 = true;
      this.name2 = ''
      for (let key in this.form2) {
        this.form2[key] = data[key];
      }
      this.form2.id = data.id;
      this.form2.typeId = this.form1.typeId;
      this.$data.table2 = this.$options.data().table2;
      if (data.inputType == 2 && data.content) {
        this.table2 = JSON.parse(data.content);
      }
      setTimeout(() => {
        this.$refs.refform2.clearValidate();
      }, 10);
    },
    Deljson(index) {
      this.table2.splice(index, 1);
    },
    Addjson() {
      if (!this.name2) {
        this.$message({
          message: "警告哦,请先输入选项值",
          type: "warning",
        });
        return;
      }
      this.table2.push({ name: this.name2 });
      this.name2 = "";
    },
    submit2() {
      this.$refs.refform2.validate((valid) => {
        if (valid) {
          if (this.form2.inputType == 2) {
            if (this.table2.length == 0) {
              this.$message({
                message: "警告哦,请至少保证有一条选项",
                type: "warning",
              });
              return;
            }
            const copyData = JSON.parse(JSON.stringify(this.table2));
            if (this.name2) {
              copyData.push({ name: this.name2 })
            }
            this.form2.content = JSON.stringify(copyData);
          }
          this.form2.companyId = this.form1.companyId
          setcheckItem(this.form2).then((res) => {
            if (res.code * 1 === 1001) {
              this.$message.success('保存成功')
              this.Dialog2 = false;
              this.gettable1();
            }

          });
        } else {
          return false;
        }
      });
    },
    gettypeList() {
      getDicType({ code: "castingType" }).then((res) => {
        this.equipmentTypelist = res.data.items;
      });
    },
    pagessubmitFromDate() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          _this.fromDate.typeName = _this.equipmentTypelist.find(function (
            obj
          ) {
            return obj.id == _this.fromDate.typeId;
          }).itemName;
          _this.submitFromDate();
        }
      });
    },
    maintenance(low) {
      this.id = low.id;
      this.maintenanceDialog = true;
      this.maintenanceData = {
        typeName: "",
        typeId: "",
        daintainTime: "",
        remark: "",
      };
      this.getmaintenancelist();
    },
    getmaintenancelist() {
      equipmentMaintainQueryPagee({
        ...this.maintenanceParam,
        pumpUnitId: this.id,
      }).then((res) => {
        this.maintenancetotal = res.data.totalRows;
        this.maintenancelist = res.data.data;
      });
    },
    submitmaintenance() {
      this.maintenanceData.daintainTime = new Date(
        this.maintenanceData.daintainTime
      ).Format("yyyy-MM-dd hh:mm:ss");
      this.maintenanceData.typeName = this.MaintenanceType.find(
        (res) => res.id == this.maintenanceData.typeId
      ).itemName;
      equipmentMaintainsave({
        ...this.maintenanceData,
        pumpUnitId: this.id,
      }).then((res) => {
        if (res.code === 1001) {
          this.$message.success('录入成功')
          this.resetOtherFromDate();
        }
      });
    },
    resetOtherFromDate() {
      this.maintenanceDialog = false;
    },
    /*重置数据*/
    init() {
      this.tableParam.typeId = "";
      this.tableParam.code = "";
      this.tableParam.company = "";
      this.tableParam.stationName = "";
      this.tableParam.plateNumbers = "";
      this.tableParam.enable = "";
      this.gettableData();
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    }
  },
};
</script>

<style lang="scss" scoped>
.checkcycdialoginfo {
  .el-input {
    width: 100px;
  }
  .el-select {
    width: 100px;
    margin-right: 20px;
  }
  .text {
    padding: 10px;
  }
}
.dialogOtherinfo {
  .el-pagination {
    padding: 10px 0;
  }
  min-height: 530px;
  .textarea {
    width: 870px;
  }

  .el-input,
  .el-select {
    width: 375px;
  }
}

.table_link {
  margin: 0 0 0 10px;
  border: $bg_color 1px solid;
  color: $bg_color;
  border-radius: 3px;
  font-size: 14px;
  height: 30px;
  background: #ffffff;
  a {
    display: inline-block;
    line-height: 29.31px;
    color: $bg_color;
    text-decoration: none;
    font-size: 14px;
  }
}

.table_link:hover {
  color: #ffffff;
  background: $bg_color;
  a {
    color: #ffffff;
  }
}
.el-dialog{
  .el-input,
  .el-select {
    width: 240px;
  }
}
.content {
  width: 100%;
  @include discen;
  > div {
    height: 47px;
  }
  > div:first-child {
    @include discen;
    width: 170px;
    border: 1px solid #e1e5ed;
    padding: 0 20px;
  }
  > div:last-child {
    @include discen;
    text-align: center;
    width: 100px;
  }
}
.content + .content {
  > div:first-child {
    border-top: 0;
  }
}
</style>
